//
//  MJMyInfoTableHeaderView.m
//  MJ
//
//  Created by qiaoBu on 2017/12/8.
//  Copyright © 2017年 lina. All rights reserved.
//

#import "MJMyInfoTableHeaderView.h"
#import "MJMeInfoModel.h"

@interface MJMyInfoTableHeaderView ()



@end

@implementation MJMyInfoTableHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame])
    {
        self.backgroundColor = [UIColor whiteColor];
        [self commonInit];
    }
    return self;
}
- (void)commonInit{
    
    _headerImageView = [[UIImageView alloc] init];
    [self addSubview:_headerImageView];
    [_headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_top).offset(15);
        make.centerX.mas_equalTo(self.mas_centerX);
        make.width.height.mas_equalTo(80);
    }];
   ViewBorderRadius(_headerImageView, 40.f, 0.5, RGBColor(217,217,217));
    
    _nameLabel = [[UILabel alloc] init];
    [self addSubview:_nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_headerImageView.mas_bottom).offset(10);
        make.centerX.mas_equalTo(self.mas_centerX);
    }];
    _nameLabel.textColor = RGBColor(102, 102, 102);
    _nameLabel.font = [UIFont systemFontOfSize:20];
    _nameLabel.textAlignment = NSTextAlignmentCenter;
    _nameLabel.text = @"褚乐青";
    
    _sexLabel = [[UILabel alloc] init];
    [self addSubview:_sexLabel];
    [_sexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_nameLabel.mas_bottom).offset(10);
        make.centerX.mas_equalTo(self.mas_centerX);
    }];
    _sexLabel.textColor = RGBColor(191, 191, 191);
    _sexLabel.font = [UIFont systemFontOfSize:16];
    _sexLabel.textAlignment = NSTextAlignmentCenter;
    _sexLabel.text = @"男";
    
    NSString *sex = [[NSUserDefaults standardUserDefaults] objectForKey:MJ_Sex];
    NSString *headerPath = [[NSUserDefaults standardUserDefaults] objectForKey:MJ_HeaderImage];
    if ((sex.length != 0)&&([sex isEqualToString:@"2"])) {
        
        _sexLabel.text = @"女";
        if (headerPath.length !=0) {
            
            [_headerImageView sd_setImageWithURL:[NSURL URLWithString:headerPath]];
        }else{
            
             _headerImageView.image = [UIImage imageNamed:@"women_pic"];
        }
    }else{
        _sexLabel.text = @"男";
        if (headerPath.length !=0) {
            
            [_headerImageView sd_setImageWithURL:[NSURL URLWithString:headerPath]];
        }else{
            
            _headerImageView.image = [UIImage imageNamed:@"man_pic"];
        }
    }
    
    NSString *name = [[NSUserDefaults standardUserDefaults] objectForKey:MJ_Name];
    if (name.length == 0) {
        
        _nameLabel.text = @"神秘人";
    }else{
        
        _nameLabel.text = name;
    }
}

//- (void)setInfoModel:(MJMeInfoModel *)infoModel{
//
//    _infoModel = nil;
//    _infoModel = infoModel;
//    NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@",infoModel.spic]];
//    [_headerImageView sd_setImageWithURL:imageUrl];
//
//    _nameLabel.text = [NSString stringWithFormat:@"%@",infoModel.alias];
//
//    NSString *sexString = [NSString stringWithFormat:@"%@",infoModel.sex];
//    if ([sexString isEqualToString:@"1"])
//    {
//        _sexLabel.text = @"男";
//    }
//    else
//    {
//        _sexLabel.text = @"女";
//    }
//}

@end
